#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 4 数据序列化和处理练习；给定一个json格式的数据；
#   [
#     {
#         "name":"Frank",
#         "age":15,
#         "genda":"男"
#     },
#     {
#         "name":"tracy",
#         "age":20,
#          "genda":"女"
#     },
#     {
#         "name":"cythia",
#         "age":21,
#          "genda":"女"
#     },
#     {
#         "name":"王五",
#         "age":19,
#        "genda":"男"
#     },
#     {
#         "name":"jackie",
#         "age":19,
#        "genda":"男"
#     }
# ]
# 1 打印输出，年龄大于20岁的人员名单；
# 2 向列表中新增数据；
# 3 统计男生和女生的人数；

import json
list1 =   [
    {
        "name":"Frank",
        "age":15,
        "genda":"男"
    },
    {
        "name":"tracy",
        "age":20,
         "genda":"女"
    },
    {
        "name":"cythia",
        "age":21,
         "genda":"女"
    },
    {
        "name":"王五",
        "age":19,
       "genda":"男"
    },
    {
        "name":"jackie",
        "age":19,
       "genda":"男"
    }
]

list2 = json.dumps(list1)
list3 = json.loads(list2)
def judge20():
    for a in list3:
        if a['age'] > 20:
            print("name:%s" % a['name'])


def insert():
    n = int(input("请输入你要添加数据数目"))
    for i in range(n):
        x = input("请输入加入数据的姓名 年龄 性别（用/隔开）：")
        xlist = x.split('/')
        dict = {
            'name': xlist[0],
            'age': xlist[1],
            'genda': xlist[2],
        }
        list3.append(dict)
    print(list3)


def count():
    count_nan = 0
    count_nv = 0
    for a in list3:
        if a['genda'] == '男':
            count_nan += 1
        if a['genda'] == '女':
            count_nv += 1
    print("男生有%d人"%count_nan)
    print("女生有%d人" % count_nv)

if __name__ == '__main__':
    judge20()
    insert()
    count()